<?php
ob_start();
?>
<Script>
window.history.forward(1);
</Script>
<?php
for ($a=1; $a<=13; $a++) {
	if (empty($_POST["input$a"])) {
		echo "kosong".$_POST["input$a"];
		exit();			
	} else {
		$input[$a]=$_POST["input$a"];
	}
}
$kd1=substr(date("Y"),2,2);
$kd2=substr((date("Y")+1),2,2);
$kd3='A'.$kd1.$kd2;

$alamat=$_POST["alamat"];
$tgl_lhr=$input[5]."-".$input[4]."-".$input[3];
require_once('main_function.php');
$cek="SELECT idSiswa from tsiswa order by idSiswa desc";
			$run1=mysql_query($cek) or die(mysql_error());
			$efek=mysql_affected_rows();
			if ($efek==0){
				
				$idsis=$kd3.'-00001';
				echo $idsis;
			}else{
				$rec_no=mysql_fetch_array($run1);
				$potong=substr($rec_no[0],6,5);

				$potong=$potong + 1;
				$nomor=$potong;
				for ($i=1;$i<=5-strlen($potong);$i++)
				{
				$nomor='0'.$nomor;
				}
				$idsis=$kd3.'-'.$nomor;
			}
	$str_query = "INSERT INTO tSiswa VALUES ('".$idsis."','".$input[1]."','".$input[2]."','".$tgl_lhr."','";
	$str_query = $str_query.$input[6]."','".$alamat."','".$input[7]."','";
	$str_query = $str_query.$input[8]."','".$input[9]."','".$input[10]."','".$input[11]."','".$input[12]."','".$input[13]."')";
	$run_query = mysql_query($str_query);
	$num_query = mysql_affected_rows();
	if ($num_query == 1) {
		header("location: create_ses.php?uname=$idsis&nm=$input[1]");
	} else {
		header('location: add_user5.php');
	}
mysql_close($konk);
ob_end_flush();
?>